# 2024/4/9 下午4:15 HFL
from time import sleep
from selenium.webdriver import ActionChains
import allure
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from api.Base import Base
from api.keyword import Keyword


class open_an_account_Page(Keyword):

    def __init__(self):
        super().__init__()
        self.username1 = '13180577872'
        self.password1 = 'a123456'
        self.url = 'http://121.43.169.97:8081/common/member/login'
        self.username = (By.ID,'keywords')
        self.password = (By.ID,'password')
        self.login_byn = (By.ID,'login-btn')
    #    借款账户
        self.account = (By.XPATH,'//*[@id="mlayout"]/div[2]/div[2]/div[1]/a')
    #     额度申请
        self.Apply_for = (By.XPATH,'//*[@id="mlayout"]/div[2]/div[2]/div[3]/div[2]/dl/dd[4]/a')
    #     填写借款额度
        self.jiek = (By.ID,'amount_account')
    #     填写详细说明
        self.xiangx = (By.XPATH,'//*[@id="mamountapply"]/div[3]/textarea')
    #     填写验证码
        self.yanz = (By.ID,'verifycode')
    #     确认提交
        self.quer = (By.XPATH,'//*[@id="mamountapply"]/div[5]/input')
        # 后台系统，用户名
        self.username2 = (By.ID,'username')
    #     密码
        self.password2 = (By.ID,'password')
    #     验证码
        self.verifycode = (By.ID,'valicode')
    #     点击登录
        self.login_byn1 = (By.XPATH,'//*[@id="loginForm"]/div[4]/input')
    # 借款管理
        self.jkfl = (By.XPATH,'/html/body/div[1]/div[2]/ul/li[2]/a')
        self.edus = (By.XPATH,'//*[@id="sidebar"]/ul/li[5]/a/span')
        self.edushenhe = (By.XPATH,'//*[@id="sidebar"]/ul/li[5]/ul/li[2]/a')
    # 搜索框
        self.sousuo = (By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[1]/div/input')
    # 下拉框位置
        self.xiala = (By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[2]/div/select')
    # 确认按钮
        self.queren = (By.XPATH,'/html/body/div[2]/div[1]/div/ul/li[3]/input')
    #     列表第一个
        self.diyi = (By.XPATH,'/html/body/div[2]/div[3]/table/tbody/tr[1]/td[2]/span')
    #     点击审核
        self.shenhe = (By.XPATH,'/html/body/div[2]/div[2]/ul/li[1]/a/span')
    #     点击通过
        self.tongguo = (By.XPATH,'/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/label[1]/input')
    #     详细说明
        self.shuom = (By.XPATH,'/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/textarea')
    #     审核验证码
        self.yzma = (By.XPATH,'/html/body/div[2]/form/table/tbody/tr[7]/td[2]/div/ul/li[1]/input')
    #     点击保存
        self.baocun = (By.XPATH,'/html/body/div[2]/form/table/tbody/tr[8]/td[2]/input[1]')
    #     审核通过文本
        self.pizhun = (By.XPATH,'//*[@id="amount_list"]/tr[1]/td[6]')
    def open_an_account(self):
        with allure.step('打开页面'):
            self.get(self.url)
            self.driver.maximize_window()
        with allure.step('输入账号'):
            self.input_text(self.username,self.username1)
        with allure.step('输入密码'):
            self.input_text(self.password,self.password1)
        with allure.step('点击登录'):
            self.click_element(self.login_byn)
        with allure.step('点击借款账户'):
            self.click_element(self.account)
        with allure.step('点击额度申请'):
            self.click_element(self.Apply_for)
        with allure.step('填写借款额度'):
            self.input_text(self.jiek,'10000')
        with allure.step('填写详细说明'):
            self.input_text(self.xiangx,'原神启动')
        with allure.step('填写验证码'):
            self.input_text(self.yanz,'8888')
        with allure.step('确认提交'):
            self.click_element(self.quer)

        with allure.step('打开后台管理系统'):
            self.get('http://121.43.169.97:8082/')
        with allure.step('输入用户名'):
            self.input_text(self.username2,'admin')
        with allure.step('输入密码'):
            self.input_text(self.password2,'HM_2023_test')
        with allure.step('输入验证码'):
            self.input_text(self.verifycode,'8888')
        with allure.step('点击登录'):
            self.click_element(self.login_byn1)
            sleep(3)
            self.click_element(self.jkfl)
            self.click_element(self.edus)
            self.click_element(self.edushenhe)

        with allure.step('切换iframe'):
            self.switch_to_iframe('iframe_box')
        with allure.step(' 搜索栏输入'):
            self.input_text(self.sousuo,self.username1)
        with allure.step('下拉框选择'):
            Select(self.find_element(self.xiala)).select_by_value('0')
        with allure.step('确认按钮'):
            self.click_element(self.queren)
        with allure.step('点击第一个'):
            self.click_element(self.diyi)
        with allure.step('点击审核'):
            self.switch_to_iframe('xubox_iframe1')
            self.click_element(self.shenhe)
        with allure.step('点击通过'):
            self.click_element(self.baocun)
            sleep(1)
        with allure.step('打开页面'):
            self.get(self.url)
            self.driver.maximize_window()
        with allure.step('输入账号'):
            self.input_text(self.username,self.username1)
        with allure.step('输入密码'):
            self.input_text(self.password,self.password1)
        with allure.step('点击登录'):
            self.click_element(self.login_byn)
        with allure.step('点击借款账户'):
            self.click_element(self.account)
        with allure.step('点击额度申请'):
            self.click_element(self.Apply_for)
        with allure.step('断言'):
            res = self.find_element(self.pizhun).text
            if res == '审核通过':
                assert res == '审核通过'
                print('审核通过')
            else:
                print('审核失败')


